package com.own.component.common.base.entity.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.own.component.common.base.entity.po.BaseSortPo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;

/**
 * BaseVo
 *
 * @author chenxueli
 * @date 2022-09-10 12:24:52
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public abstract class BaseSortVo<T extends BaseSortPo> extends BaseVo<T> implements Serializable {

    @Schema(title = "顺序，默认数字越小约在前面")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer sortOrder;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public BaseSortVo(@NonNull T entity) {
        super(entity);
        this.sortOrder = entity.getSortOrder();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public T toPo(T entity) {
        if (entity != null) {
            entity.setSortOrder(this.sortOrder);
        }
        return super.toPo(entity);
    }

}
